package com.activitycode.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;

import com.activitycode.datamodel.find.EvaluateEntity;
import com.activitycode.datamodel.ground.StoreComment;
import com.activitycode.tools.OptionsTool;
import com.activitycode.util.CommConstant;
import com.duostec.zhuyue.pets.R;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

public class EvaluateAdapter extends BaseAdapter {
	
	public Context context;
	private List<StoreComment> infoList;
	public EvaluateAdapter adapter;
	private ImageLoader imageLoader = ImageLoader.getInstance();
	private DisplayImageOptions headOptions;
	private DisplayImageOptions sexOptions;
	
	public EvaluateAdapter(Context context,List<StoreComment> infoList) {
		this.context = context;
		this.infoList = infoList;
		headOptions = OptionsTool.getHeadOptions(context);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return infoList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return infoList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		ViewHolder viewHolder;
		if(convertView == null){
			convertView = LayoutInflater.from(context).inflate(
					R.layout.adapter_evaluate, null);
			viewHolder = new ViewHolder();
			viewHolder.evalIcon = (ImageView)convertView.findViewById(R.id.evaluate_head_image);
			viewHolder.evalSex = (ImageView)convertView.findViewById(R.id.evaluate_sex_image);
			viewHolder.evalName = (TextView)convertView.findViewById(R.id.evaluate_name);
			viewHolder.evalWords = (TextView)convertView.findViewById(R.id.evaluate_words);
			viewHolder.evalLike =  (RatingBar)convertView.findViewById(R.id.ratingBar1);
			convertView.setTag(viewHolder);
		}else{
			viewHolder = (ViewHolder) convertView.getTag();
		}
		imageLoader.displayImage(CommConstant.SERVICE_HOST_IP_LAN_IMG+infoList.get(position).getHead_image(), viewHolder.evalIcon, headOptions);
		viewHolder.evalLike.setRating(Float.parseFloat(infoList.get(position).getComment_score()));;
		viewHolder.evalName.setText(infoList.get(position).getNick_name());
		viewHolder.evalWords.setText(infoList.get(position).getContent());
		
		if(infoList.get(position).getSex().equals("0")){
			
			viewHolder.evalSex.setBackground(context.getResources().getDrawable(R.drawable.male2));
		}
		else{
			viewHolder.evalSex.setBackground(context.getResources().getDrawable(R.drawable.female));
			}
		
		// TODO Auto-generated method stub
		return convertView;
	}
	
	final static class ViewHolder{
		private ImageView evalIcon;
		private ImageView evalSex;
		private TextView evalName;
		private TextView evalWords;
		private RatingBar evalLike;
		
	} 

}
